/*
 * ServerFacade.java
 *
 * Dunsel - Java library for asymmetric peer-to-peer content streaming
 * Copyright (C) 2009 by Matthew Werny
 * All Rights Reserved
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */
package net.iceflow.dunsel.server.interfaces;

import net.iceflow.dunsel.commons.exception.PortOutOfRangeException;
import net.iceflow.dunsel.server.exception.StreamProviderLimitExceededException;

/** Facade that simplifies interactions with the Dunsel server library. */
public interface ServerFacade {

   /**
    * Gets the depth of clients that should be considered to be superpeers and be allowed to directly connect to a stream source.
    * @return Number of levels to consider super-peers beyond the second level
    */
   int getSuperPeerDepth();

   /**
    * Sets the depth of clients that should be considered to be superpeers and be allowed to directly connect to a stream source.
    * @param depth Number of levels to consider super-peers beyond the second level
    */
   void setSuperPeerDepth(int depth);

   /**
    * Gets the maximum size (in bytes) of the payload of a single frame.
    * @return maximum size (in bytes)
    */
   int getMaxFramePayloadSize();

   /**
    * Gets the maximum size (in bytes) of the payload of a single frame.
    * @param size maximum size (in bytes)
    */
   void setMaxFramePayloadSize(int size);

   /**
    * Adds a stream provider to the server instance to have its source data be consumed and streamed.
    * @param provider Provider instance to add
    * @throws StreamProviderLimitExceededException If more than the allowable limit of stream providers is attempted to be added
    */
   void addStreamProvider(StreamProvider provider) throws StreamProviderLimitExceededException;

   /**
    * Removes a stream provider from the server instance.
    * @param provider Provider instance to add
    */
   void removeStreamProvider(StreamProvider provider);

   /** Attempts to start the server and have it accept client connections. */
   void start();

   /**
    * Attempts to start the server and have it accept client connections on a specific port.
    * @param controlPort Port to which to connect for control connections
    * @param streamingPort Port to which to connect for streaming
    * @throws PortOutOfRangeException If either controlPort or streamingPort are out of their valid ranges
    */
   void start(int controlPort, int streamingPort) throws PortOutOfRangeException;

   /** Attempts to stop the server and have it terminate any active client connections. */
   void stop();

   /**
    * Indicates whether the facade is in a running state.
    * @return Truth of whether it is running
    */
   boolean isStarted();
}
